home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / CDragAndDrop / CDragTask.cp < prev    next >
Encoding:
Text File  |  1995-02-09  |  4.2 KB  |  123 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    CDragTask.h                ©1995 J. Rodden, DD/MF & Associates. All rights reserved
  3. // =================================================================================
  4. // You do not need to inherit this class.
  5. //
  6. // LDragTask gives us general drag functionality and behaviour.  CDragTask exists so
  7. // that we can add behaviour specific to dragging our items without having to inherit
  8. // from LDragTask anymore.
  9. //
  10. // CDragTask actually acts as a stub object, it passes the work onto the object being
  11. // dragged so that all drag manager code can be isolated in the object being dragged
  12. // or its owner and you don't ever have to deal with an LDragTask again.
  13. //
  14. // By using CDragTask and overriding AddFlavors and MakeDragRegion in the object 
  15. // being dragged, you can (a) include as many flavors of an item as you want, (b) 
  16. // define your own outline to replace the generic rectangle that LDragTask provides,
  17. // (c) arrange to send drag data on demand by calling InstallDragSendData when
  18. // adding flavors (and installing null data in the drag) and overriding DoSendDragData
  19. // for the object being dragged, and (d) override the drag manager's default behaviors
  20. // for DragInput and DragDrawing by calling InstallDragInput or InstallDragDrawing
  21. // and overriding DoDragInput or DoDragDrawing respectively.
  22. // =================================================================================
  23.  
  24. #include "CDragTask.h"
  25. #include "CDragItem.h"
  26.  
  27. // =================================================================================
  28. //        • CDragTask
  29. // =================================================================================
  30.  
  31. CDragTask::CDragTask(
  32.     const EventRecord    &inEventRecord,
  33.     CDragItem*            inDragItem)
  34.     
  35.     : LDragTask(inEventRecord),
  36.       dragItem(inDragItem)
  37. {
  38. }
  39.  
  40.  
  41. // =================================================================================
  42. //        • CDragTask
  43. // =================================================================================
  44.  
  45. CDragTask::CDragTask (
  46.     const EventRecord&    inEventRecord,
  47.     const Rect*            inItemRect,
  48.     ItemReference        inItemRef,
  49.     CDragItem*            inDragItem)
  50.  
  51.     : LDragTask(inEventRecord),
  52.       dragItem(inDragItem)
  53. {
  54.     if ( inItemRect != nil ) {                // optionally provide default drag outline
  55.         Rect    globalRect = *inItemRect;
  56.       ::LocalToGlobal(&topLeft(globalRect));
  57.       ::LocalToGlobal(&botRight(globalRect));
  58.         AddRectDragItem(inItemRef, globalRect);
  59.     }
  60. }
  61.  
  62.  
  63. // =================================================================================
  64. //        • AddFlavors
  65. // =================================================================================
  66. // Let the object being dragged add the drag flavors.
  67.  
  68. void
  69. CDragTask::AddFlavors (DragReference inDragRef)
  70. {
  71.     if (dragItem) dragItem->AddFlavors(inDragRef);
  72. }
  73.  
  74.  
  75. // =================================================================================
  76. //        • MakeDragRegion
  77. // =================================================================================
  78. // Let the object being dragged make the drag region.
  79.  
  80. void
  81. CDragTask::MakeDragRegion( DragReference inDragRef, RgnHandle inDragRegion)
  82. {
  83.     if (dragItem) dragItem->MakeDragRegion(inDragRef,inDragRegion);
  84. }
  85.  
  86.  
  87. // =================================================================================
  88. //        • InstallDragSendData
  89. // =================================================================================
  90. // Let the object being dragged override default DragSendData behavior.
  91.  
  92. void
  93. CDragTask::InstallDragSendData()
  94. {
  95.     if (dragItem) dragItem->InstallDragSendData(mDragRef);
  96. }
  97.  
  98.  
  99. // =================================================================================
  100. //        • InstallDragInput
  101. // =================================================================================
  102. // Let the object being dragged override default DragInput behavior.
  103.  
  104. void
  105. CDragTask::InstallDragInput()
  106. {
  107.     if (dragItem) dragItem->InstallDragInput(mDragRef);
  108. }
  109.  
  110.  
  111. // =================================================================================
  112. //        • InstallDragDrawing
  113. // =================================================================================
  114. // Let the object being dragged override default DragDrawing behavior.
  115.  
  116. void
  117. CDragTask::InstallDragDrawing()
  118. {
  119.     if (dragItem) dragItem->InstallDragDrawing(mDragRef);
  120. }
  121.  
  122.  
  123.